package com.mt.system.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.mt.common.ServiceResult;
import com.mt.common.constants.BaseErrorConstants;
import com.mt.system.api.service.IAdminRoleRelateService;
import com.mt.system.entity.AdminRoleRelateEntity;
import com.mt.system.service.model.AdminRoleRelateServiceModel;

@Service
public class AdminRoleRelateServiceImpl implements IAdminRoleRelateService {

    private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(AdminRoleRelateServiceImpl.class);

    @Autowired
    private AdminRoleRelateServiceModel adminRoleRelateServiceModel;

    public ServiceResult<AdminRoleRelateEntity> findInfo(Map<String, Object> params) {
        // 查询用户信息
        ServiceResult<AdminRoleRelateEntity> result = null;
        try {
            result = adminRoleRelateServiceModel.selectInfo(params);
        } catch (Exception e) {
            LOGGER.error("[AdminRoleRelateServiceImpl][findInfo]：query findInfo occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "查询详情错误");
        }
        return result;
    }

    public ServiceResult<List<AdminRoleRelateEntity>> findList(Map<String, Object> params) {
        ServiceResult<List<AdminRoleRelateEntity>> result = new ServiceResult<List<AdminRoleRelateEntity>>();
        try {
            result = adminRoleRelateServiceModel.selectList(params, null);
        } catch (Exception e) {
            LOGGER.error("[AdminRoleRelateServiceImpl][findList]：query findList occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "查询列表错误");
        }
        return result;
    }

    public ServiceResult<Integer> doInsert(AdminRoleRelateEntity adminRoleRelateEntity) {
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        try {
            result = adminRoleRelateServiceModel.insert(adminRoleRelateEntity);
        } catch (Exception e) {
            LOGGER.error("[AdminRoleRelateServiceImpl][doInsert]：query doInsert occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "创建信息错误");
        }
        return result;
    }

    public ServiceResult<Integer> doUpdate(AdminRoleRelateEntity adminRoleRelateEntity) {
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        try {
            result = adminRoleRelateServiceModel.updateByPrimaryKeySelective(adminRoleRelateEntity);
        } catch (Exception e) {
            LOGGER.error("[AdminRoleRelateServiceImpl][doUpdate]：query doUpdate occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "更新信息错误.");
        }
        return result;
    }

    public ServiceResult<Integer> doDeleteByUserId(Integer userId) {
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        try {
            result = adminRoleRelateServiceModel.deleteByPrimaryKey(userId);
        } catch (Exception e) {
            LOGGER.error("[AdminRoleRelateServiceImpl][doDeleteById]：query doDeleteById occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "删除信息错误");
        }
        return result;
    }

}
